#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define all(x) (x).begin(),(x).end()
typedef long long ll;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;

typedef pair<int,int> PII;
typedef vector<PII> VPII;
#define X first
#define Y second
#define mp make_pair

#define two(x) (1<<(x))
#define twoll(x) ((long long)1<<(x))
#define contain(s,x) (((s)&two(x))!=0)
#define containll(s,x) (((s)&twoll(x))!=0)

#define db(a) cout << #a << "=" << a << " "
#define dbn cout << endl
#define sqr(x) (x)*(x)

string STR(int n) { char tmp[20]; sprintf(tmp,"%d",n); return tmp; }
int INT(string s) { return atoi(s.c_str()); }
template <class Ty, class Tx> Ty to(const Tx &x) { Ty y; stringstream ss; ss<<x; ss>>y; return y; }

const int INF = 1000000007;
const double EPS = 1e-10;

char buf[1<<20];
int TC;

string pad[4] = {
		"123",
		"456",
		"789",
		"*0#"
};

int id[4][3] = {
		{1,2,3},
		{4,5,6},
		{7,8,9},
		{10,11,12}
};

double getA(int a, int b) {
	if (a > b) swap(a,b);
	int ar,ac,br,bc;
	for (int i = 0; i < 4; ++i)
		for (int j = 0; j < 3; ++j)
			if (id[i][j] == a)
				ar = i, ac = j;
			else if (id[i][j] == b)
				br = i, bc = j;
	if (ar == br)
		return 0;
	if (ac == bc)
		return INF;
	if (ac > bc)
		return abs((ar-br)*1.0/(ac-bc));
	else
		return -abs((ar-br)*1.0/(ac-bc));
}

bool sameA(double a, double b) {
	if (abs(a-b) < EPS)
		return 1;
	return 0;
}

VI getSeq(int a, int b, double A) {
	if (a > b) swap(a,b);
	VI v;
	int ar,ac,br,bc;
	for (int i = 0; i < 4; ++i)
		for (int j = 0; j < 3; ++j)
			if (id[i][j] == a)
				ar = i, ac = j;
			else if (id[i][j] == b)
				br = i, bc = j;
	if (sameA(0,A)) {
		for (int i = a; i <= b; ++i)
			v.push_back(i);
	}
	else if (sameA(INF,A)) {
		for (int i = ar; i <= br; ++i)
			v.push_back(id[i][ac]);
	}
	else if (sameA(1,A)) {
		for (int i = ar, k = 0; i <= br; ++i, ++k)
			v.push_back(id[i][ac-k]);
	}
	else if (sameA(-1,A)) {
		for (int i = ar, k = 0; i <= br; ++i, ++k)
			v.push_back(id[i][ac+k]);
	}
	else {
		v.push_back(a);
		v.push_back(b);
	}
	sort(all(v));
	return v;
}

struct Line {
	Line(int a, int b) {
		angle = getA(a,b);
		seq = getSeq(a,b,angle);
	};
	double angle;
	VI seq;
};

bool can(Line a, Line b) {
	if (sameA(a.angle,b.angle))
		for (int i = 0; i < a.seq.size(); ++i)
			for (int j = 0; j < b.seq.size(); ++j)
				if (a.seq[i] == b.seq[j])
					return 1;
	return 0;
}

Line comb(Line a, Line b) {
	int c = min(a.seq[0],b.seq[0]);
	int d = max(a.seq.back(),b.seq.back());
	return Line(c,d);
}

int main() {
#define SUBMIT 0
#if !SUBMIT
	freopen("DATA.in", "rt", stdin);
	freopen("DATA.ou", "wt", stdout);
#endif

	gets(buf); TC = atoi(buf);
	
	while (TC--) {
		gets(buf);
		string str = buf;
		VI v;
		for (int i = 0; i < str.length(); ++i) {
			for (int r = 0; r < 4; ++r)
				for (int c = 0; c < 3; ++c)
					if (str[i] == pad[r][c])
						v.push_back(id[r][c]);
		}
		
		vector<Line> vl;
		for (int i = 0; i < v.size()-1; ++i) {
			if (v[i] == v[i+1])
				continue;
			vl.push_back(Line(v[i],v[i+1]));
		}
		
		bool c = 1;
		while (c) {
			c = 0;
			for (int i = 0; i < vl.size(); ++i)
				for (int j = i+1; j < vl.size(); ++j)
					if (can(vl[i],vl[j])) {
						c = 1;
						vl.push_back(comb(vl[i],vl[j]));
						vl.erase(vl.begin()+j);
						vl.erase(vl.begin()+i);
						goto next;
					}
			next:;
		}
		if (vl.size() <= 3)
			printf("EXCELLENT\n");
		else if (vl.size() == 4)
			printf("GOOD\n");
		else
			printf("BAD\n");
	}

	return 0;
}





